﻿namespace ZQNB.Common.Encrypt
{
    //常用的加密相关的类
    public class NbEncryptHelper
    {
        private readonly MySymmetricCryptoHelper _symmetricCryptoHelper = new MySymmetricCryptoHelper("zqnbzqnb", ")(*&3gi8JoG&D0g=");
        private readonly MyHashHelper _hashHelper = new MyHashHelper();
        private readonly MyRandomHelper _randomHelper = new MyRandomHelper();

        public string SignByPrivateKey(string inputString, string xmlPrivateKey)
        {
            string result = MySignatureHelper.SignByPrivateKey(inputString, xmlPrivateKey);
            return result;
        }
        public bool VerifyByPublicKey(string inputString, string xmlPublicKey, string signature)
        {
            bool result = MySignatureHelper.VerifyByPublicKey(inputString, xmlPublicKey, signature);
            return result;
        }

        public string Hash(string inputString)
        {
            string hash = _hashHelper.ComputeHash(inputString);
            return hash;
        }

        public string EncryptSymmetric(string inputText)
        {
            string result = _symmetricCryptoHelper.EncryptString(inputText);
            return result;
        }
        public string DecryptSymmetric(string inputText)
        {
            string result = _symmetricCryptoHelper.DecryptString(inputText);
            return result;
        }

        public string EncryptASymmetric(string inputString, string xmlPrivateKey)
        {
            string result = MyAsymmetricCryptoHelper.EncryptByPrivateKey(inputString, xmlPrivateKey);
            return result;
        }
        public string DecryptASymmetric(string inputString, string xmlPrivateKey)
        {
            string result = MyAsymmetricCryptoHelper.DecryptByPrivateKey(inputString, xmlPrivateKey);
            return result;
        }

        public string GenerateRandomString(int keySize, int samllCharAsciiCode, int bigCharAsciiCode)
        {
            return _randomHelper.GetRandomKey(keySize, samllCharAsciiCode, bigCharAsciiCode);
        }
    }
}